<!--  -->
<template>
  <div class="menu">
    <el-input
      placeholder="输入关键字进行过滤"
      v-model="filterText">
    </el-input>

    <el-tree
      class="filter-tree"
      :data="goodsCategories"
      :props="defaultProps"
      :filter-node-method="filterNode"
      :highlight-current="true"
      :draggable="true"
      :default-expand-all="true"
      @node-click='nodeClick'
      ref="tree">
    </el-tree>
  </div>
</template>

<script>
export default {
  data () {
    return {
      filterText: '',
      // 商品分类展示
      goodsCategories:[],
      defaultProps: {
        children: "children",
        label: "name",
      },
    };
  },
  created(){
    this.getDataList()
  },
  watch: {
      filterText(val) {
        this.$refs.tree.filter(val);
      }
    },
  methods: {
    async  getDataList(){
      const {data:res} = await this.$http.get("/dqxmall/prosyscategory/list/tree")
      this.goodsCategories = res.data
    },
    // 过滤方法
    filterNode(value, data) {
      console.log(data)
        if (!value) return true;
        return data.name.indexOf(value) !== -1;
      },
    nodeClick(data,node,component){
      // 想父组件发送事件
      this.$emit('tree-node-click', data,node,component);
    },
  },
}

</script>
<style lang='less' scoped>
.menu{
  margin-top: 20px;
}
</style>